package com.avicit.zipkinkafkaesserver.dto;

import com.avicit.zipkinkafkaesserver.utils.JsonUtils;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Map;

/**
 * 接口调用次数统计
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ZipkinInterfaceCountDto implements Serializable {

  private Long id;
  private String interfaceIp;
  private Integer serverPort;
  private String serverName;
  private String interfacePath;
  private String interfaceStatus;
  /**
   * 接口调用的总次数
   */
  private Integer interfaceCount;

  //记录数据属于的哪天,方便查询
  private Date queryDate;

  //server-a@GET@/getInfo
  private String interfaceKey;
  private String queryKey;
  //抓取es 记录中的开始时间
  private Long esStartTime;
  //抓取es 记录中的结束时间
  private Long esEndTime;

  /**
   * 对应的 ok 次数
   */
  private Integer ok;
  /**
   *
   * error 次数
   */
  private Integer error;


  @Temporal(TemporalType.TIMESTAMP)
  @CreationTimestamp
  private Date createTime;
  @Temporal(TemporalType.TIMESTAMP)
  @UpdateTimestamp
  private Date updateTime;

  //记录接口成功次数和失败次数json
  private String errorOk;

  public void setErrorOk(Map<String,Integer> errorOkCount) {
    this.errorOk = JsonUtils.BeanToJsonString(errorOkCount);
  }

  public Map<String,Integer> getErrorOk() {
    return (Map<String,Integer>)JsonUtils.JsonStringToBean(this.errorOk,Map.class);
  }


}
